<template>
  <div class="app-container">
    <el-row :gutter="20" class="main-content">
      <splitpanes :horizontal="this.$store.getters.device === 'mobile'" class="default-theme">
        <!--部门数据-->
        <pane size="20" min-size="15" class="tree-pane">
          <el-col class="tree-column">
            <div class="head-container">
              <el-input v-model="deptName" placeholder="请输入部门名称" clearable size="small" prefix-icon="el-icon-search"
                style="margin-bottom: 20px" />
            </div>
            <div class="tree-container">
              <el-tree :data="deptOptions" :props="defaultProps" :expand-on-click-node="false"
                :filter-node-method="filterNode" :default-expanded-keys="defaultExpandedKeys" ref="tree" node-key="id"
                highlight-current @node-click="handleNodeClick" />
            </div>
          </el-col>
        </pane>

        <!--ADSL数据-->
        <pane size="80" min-size="70">
          <el-col style="height: 100%; display: flex; flex-direction: column;">
            <el-card class="search-card" shadow="hover" style="flex-shrink: 0;">
              <div slot="header" class="search-header">
                <span><i class="el-icon-search"></i> 搜索条件</span>
                <el-button style="float: right; padding: 3px 0" type="text" @click="toggleAdvanced">
                  {{ showAdvanced ? '收起' : '展开' }}高级搜索
                  <i :class="showAdvanced ? 'el-icon-arrow-up' : 'el-icon-arrow-down'"></i>
                </el-button>
              </div>
              <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
                label-width="75px">
                <!-- 基础搜索条件 -->
                <div class="search-section basic-search">
                  <el-form-item label="机主姓名" prop="jzxm">
                    <el-input v-model="queryParams.jzxm" placeholder="请输入机主姓名" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item label="装机地址" prop="address">
                    <el-input v-model="queryParams.address" placeholder="请输入装机地址" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item label="房主手机" prop="landlordPhone">
                    <el-input v-model="queryParams.landlordPhone" placeholder="请输入房主手机号" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
                  </el-form-item>
                </div>

                <!-- 高级搜索条件 -->
                <div class="search-section advanced-search" v-show="showAdvanced">
                  <div class="divider">
                    <span class="divider-title">接入信息</span>
                  </div>
                  <el-form-item label="门禁编码" prop="mjbm">
                    <el-input v-model="queryParams.mjbm" placeholder="请输入门禁编码" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item label="宽带账号" prop="kdzh">
                    <el-input v-model="queryParams.kdzh" placeholder="请输入宽带账号" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item label="4G卡号" prop="sgk">
                    <el-input v-model="queryParams.sgk" placeholder="请输入4G卡号" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>

                  <div class="divider">
                    <span class="divider-title">安装信息</span>
                  </div>
                  <el-form-item label="装锁人员" prop="zsry">
                    <el-input v-model="queryParams.zsry" placeholder="请输入装锁人员" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>
                  <el-form-item label="验收状态" prop="sfys">
                    <el-input v-model="queryParams.sfys" placeholder="请输入验收状态" clearable
                      @keyup.enter.native="handleQuery" />
                  </el-form-item>
                </div>
              </el-form>
            </el-card>

            <el-row :gutter="10" class="mb8" style="flex-shrink: 0;">
              <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd">新增</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single"
                  @click="handleUpdate">修改</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple"
                  @click="handleDelete">删除</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="info" plain icon="el-icon-upload2" size="mini" @click="handleImport">导入</el-button>
              </el-col>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>

            <div class="table-container" style="flex: 1; display: flex; flex-direction: column; overflow: hidden;">
              <div class="table-wrapper">
                <el-table v-loading="loading" :data="adslList" @selection-change="handleSelectionChange" border
                  :height="tableHeight" style="width: 100%; flex: 1;">
                  <el-table-column type="selection" width="55" align="center" fixed="left" />
                  <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="280"
                    fixed="left">
                    <template slot-scope="scope">
                      <el-button size="mini" type="text" icon="el-icon-edit"
                        @click="handleUpdate(scope.row)">修改</el-button>
                      <el-button size="mini" type="text" icon="el-icon-key"
                        @click="handleChangeGuid(scope.row)">修改GUID</el-button>
                      <el-button size="mini" type="text" icon="el-icon-time"
                        @click="handleViewGuidHistory(scope.row)">GUID记录</el-button>
                      <el-button size="mini" type="text" icon="el-icon-delete"
                        @click="handleDelete(scope.row)">删除</el-button>
                    </template>
                  </el-table-column>
                  <el-table-column label="房主姓名" align="center" prop="landlordName" />
                  <el-table-column label="房主手机" align="center" prop="landlordPhone" />

                  <el-table-column label="合同编号" align="center" prop="htbh" />
                  <el-table-column label="公司" align="center" prop="countryName" />
                  <el-table-column label="省" align="center" prop="provinceName" />
                  <el-table-column label="所属市" align="center" prop="cityName" />
                  <el-table-column label="所属区" align="center" prop="districtName" />
                  <el-table-column label="所属镇" align="center" prop="streetName" />
                  <el-table-column label="所属村" align="center" prop="villageName" />
                  <el-table-column label="装机地址" align="center" prop="address" show-overflow-tooltip />
                  <el-table-column label="标准地址" align="center" prop="standardAddress" show-overflow-tooltip />
                  <el-table-column label="机主姓名" align="center" prop="jzxm" />
                  <el-table-column label="旧GUID码" align="center" prop="jguid" show-overflow-tooltip width="140" />
                  <!-- <el-table-column label="旧GUID码" align="center" prop="oldGuid" show-overflow-tooltip width="140" /> -->
                  <el-table-column label="新GUID码" align="center" prop="xguid" show-overflow-tooltip width="140" />
                  <el-table-column label="装机联系电话" align="center" prop="zjlxdh" />
                  <el-table-column label="是否带视频" align="center" prop="sfdsp" width="100">
                  </el-table-column>
                  <el-table-column label="身份证号" align="center" prop="sfzh" show-overflow-tooltip />
                  <el-table-column label="现场是否装视频" align="center" prop="xcsfzsp" width="120">
                  </el-table-column>
                  <el-table-column label="门禁系统平台" align="center" prop="mjgs" />
                  <el-table-column label="安装时间" align="center" prop="azsj" width="120">
                  </el-table-column>
                  <el-table-column label="签名" align="center" prop="qm" />
                  <el-table-column label="装锁时间" align="center" prop="zssj" width="120">
                  </el-table-column>
                  <el-table-column label="装锁人员" align="center" prop="zsry" />
                  <el-table-column label="是否装锁" align="center" prop="sfzs" width="100">
                  </el-table-column>
                  <el-table-column label="是否装闭门器" align="center" prop="sfzbmq" width="120">
                  </el-table-column>
                  <el-table-column label="是否验收" align="center" prop="sfys" width="100">
                  </el-table-column>
                  <el-table-column label="验收批次" align="center" prop="yspc" />
                  <el-table-column label="4G卡号" align="center" prop="sgk" />
                  <el-table-column label="门禁编码" align="center" prop="mjbm" />
                  <!-- <el-table-column label="门禁编码" align="center" prop="adsljrh" /> -->
                  <el-table-column label="宽带账号" align="center" prop="kdzh" />
                  <el-table-column label="宽带密码" align="center" prop="kdmm" show-password />
                  <el-table-column label="电信反馈" align="center" prop="dxfk" show-overflow-tooltip />
                  <el-table-column label="屋主反馈" align="center" prop="fzfk" show-overflow-tooltip />
                  <el-table-column label="整体备注" align="center" prop="ztbz" show-overflow-tooltip />
                  <el-table-column label="资料不齐" align="center" prop="zlbq" show-overflow-tooltip />
                  <el-table-column label="资料变更" align="center" prop="zlbg" show-overflow-tooltip />
                  <el-table-column label="特殊情况" align="center" prop="tsqk" show-overflow-tooltip />
                </el-table>
              </div>

              <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" style="flex-shrink: 0; margin-top: 10px;" />
            </div>
          </el-col>
        </pane>
      </splitpanes>
    </el-row>

    <!-- 添加或修改ADSL资料对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1100px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <!-- 基本信息 -->
        <div class="section-title">基本信息</div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="合同编号" prop="htbh">
              <el-input v-model="form.htbh" placeholder="请输入合同编号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="公司" prop="company">
              <el-input v-model="form.company" placeholder="请输入公司" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="地区" prop="deptId">
              <el-cascader v-model="form.deptId" :options="addressTreeOptions" :props="{
                expandTrigger: 'hover',
                checkStrictly: true,
                value: 'id',
                label: 'label',
                children: 'children',
                emitPath: true
              }" clearable style="width: 100%" placeholder="请选择地区" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="装机地址" prop="address">
              <el-input v-model="form.address" placeholder="请输入详细地址" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="标准地址" prop="standardAddress">
              <el-input v-model="form.standardAddress" placeholder="请输入标准地址" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 机主信息 -->
        <div class="section-title">机主信息</div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="机主姓名" prop="jzxm">
              <el-input v-model="form.jzxm" placeholder="请输入机主姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证件号码" prop="sfzh">
              <el-input v-model="form.sfzh" placeholder="请输入证件号码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="zjlxdh">
              <el-input v-model="form.zjlxdh" placeholder="请输入联系电话" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="是否带视频" prop="sfdsp">
              <el-select v-model="form.sfdsp" placeholder="请选择是否带视频">
                <el-option label="是" value="1" />
                <el-option label="否" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="现场视频状态" prop="xcsfzsp">
              <el-select v-model="form.xcsfzsp" placeholder="请选择现场是否装视频">
                <el-option label="已装" value="1" />
                <el-option label="未装" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="安装时间" prop="azsj">
              <el-date-picker v-model="form.azsj" type="datetime" placeholder="选择安装时间"
                value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- GUID码信息 -->
        <div class="section-title">GUID码信息</div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="旧GUID码" prop="jguid">
              <el-input v-model="form.jguid" placeholder="请输入机主GUID码" />
            </el-form-item>
          </el-col>
          <!-- <el-col :span="8">
            <el-form-item label="旧GUID码" prop="oldGuid">
              <el-input v-model="form.oldGuid" placeholder="请输入旧GUID码" />
            </el-form-item>
          </el-col> -->
          <el-col :span="8">
            <el-form-item label="新GUID码" prop="xguid">
              <el-input v-model="form.xguid" placeholder="请输入新GUID码" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 门禁信息 -->
        <div class="section-title">门禁信息</div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="门禁系统" prop="mjgs">
              <el-input v-model="form.mjgs" placeholder="请输入门禁系统平台" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="门禁编码" prop="mjbm">
              <el-input v-model="form.mjbm" placeholder="请输入门禁编码" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="签名" prop="qm">
              <el-input v-model="form.qm" placeholder="请输入施工人员签名" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 装锁信息 -->
        <div class="section-title">装锁信息</div>
        <el-row>
          <el-col :span="8">
            <el-form-item label="装锁状态" prop="sfzs">
              <el-select v-model="form.sfzs" placeholder="请选择装锁状态">
                <el-option label="已装锁" value="1" />
                <el-option label="未装锁" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="装锁时间" prop="zssj">
              <el-date-picker v-model="form.zssj" type="datetime" placeholder="选择装锁时间"
                value-format="yyyy-MM-dd HH:mm:ss" style="width: 100%" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="装锁人员" prop="zsry">
              <el-input v-model="form.zsry" placeholder="请输入装锁人员" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="装闭门器" prop="sfzbmq">
              <el-select v-model="form.sfzbmq" placeholder="请选择闭门器状态">
                <el-option label="已装" value="1" />
                <el-option label="未装" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="验收状态" prop="sfys">
              <el-select v-model="form.sfys" placeholder="请选择验收状态">
                <el-option label="已验收" value="1" />
                <el-option label="未验收" value="0" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="验收批次" prop="yspc">
              <el-input v-model="form.yspc" placeholder="请输入验收批次" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 宽带信息 -->
        <div class="section-title">宽带信息</div>
        <el-row>
          <el-col :span="8">
                 <el-form-item label="4G卡号" prop="sgk">
              <el-input v-model="form.sgk" placeholder="请输入4G卡号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="宽带账号" prop="kdzh">
              <el-input v-model="form.kdzh" placeholder="请输入宽带账号" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="宽带密码" prop="kdmm">
              <el-input v-model="form.kdmm" placeholder="请输入宽带密码" show-password />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="8">
            <el-form-item label="4G卡号" prop="sgk">
              <el-input v-model="form.sgk" placeholder="请输入4G卡号" />
            </el-form-item>
          </el-col>
        </el-row> -->

        <!-- 反馈信息 -->
        <div class="section-title">反馈信息</div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="电信反馈" prop="dxfk">
              <el-input v-model="form.dxfk" placeholder="请输入电信反馈" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="屋主反馈" prop="fzfk">
              <el-input v-model="form.fzfk" placeholder="请输入屋主反馈" />
            </el-form-item>
          </el-col>
        </el-row>

        <!-- 备注信息 -->
        <div class="section-title">备注信息</div>
        <el-row>
          <el-col :span="12">
            <el-form-item label="整体备注" prop="ztbz">
              <el-input v-model="form.ztbz" placeholder="请输入整体备注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="资料不齐" prop="zlbq">
              <el-input v-model="form.zlbq" placeholder="请输入资料不齐备注" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="资料变更" prop="zlbg">
              <el-input v-model="form.zlbg" placeholder="请输入资料变更备注" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="特殊情况" prop="tsqk">
              <el-input v-model="form.tsqk" placeholder="请输入特殊情况备注" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- ADSL资料导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="500px" append-to-body
      :close-on-click-modal="false">
      <div class="import-container">
        <div class="import-tips" v-if="!upload.isUploading && !upload.isProcessing">
          <p>请先下载ADSL资料导入模板，按照模板格式填写数据后导入：</p>
          <el-button type="text" icon="el-icon-download" @click="importTemplate">下载模板</el-button>
        </div>

        <!-- 文件选择区域 -->
        <div v-if="!upload.isUploading && !upload.isProcessing">
          <el-divider content-position="center">选择文件</el-divider>
          <div class="file-info" v-if="uploadFileName">
            <i class="el-icon-document"></i>
            <span>{{ uploadFileName }}</span>
            <el-button type="text" icon="el-icon-delete" @click="clearUploadFile">清除</el-button>
          </div>
          <div class="upload-area" v-else @click="triggerFileInput">
            <input type="file" ref="fileInput" accept=".xlsx, .xls" style="display: none;" @change="handleFileChange" />
            <i class="el-icon-upload"></i>
            <div class="upload-text">点击选择Excel文件</div>
            <div class="upload-tip">仅支持.xlsx和.xls格式</div>
          </div>
        </div>

        <!-- 导入进度区域 -->
        <div v-if="upload.isUploading" class="import-progress">
          <div class="progress-header">
            <i class="el-icon-loading"></i>
            <span>{{ upload.statusText }}</span>
          </div>

          <el-progress :percentage="upload.progress" :status="upload.progressStatus || undefined" :stroke-width="12"
            :show-text="true"></el-progress>
        </div>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitImport"
          :loading="upload.isUploading" :disabled="!uploadFile || upload.isUploading">
          {{ upload.isUploading ? '导入中...' : '确 定' }}
        </el-button>
        <el-button @click="closeImportDialog" :disabled="upload.isUploading">
          {{ upload.isUploading ? '处理中...' : '取 消' }}
        </el-button>
      </div>
    </el-dialog>

    <!-- 修改GUID对话框 -->
    <el-dialog title="修改GUID" :visible.sync="guidDialog.open" width="500px" append-to-body>
      <el-form ref="guidForm" :model="guidForm" :rules="guidRules" label-width="120px">
        <el-form-item label="当前GUID" prop="currentGuid">
          <el-input v-model="guidForm.currentGuid" placeholder="当前GUID" readonly />
        </el-form-item>
        <el-form-item label="新GUID" prop="xguid">
          <el-input v-model="guidForm.xguid" placeholder="请输入新的GUID" clearable />
        </el-form-item>
        <el-form-item label="更换原因" prop="reason">
          <el-input v-model="guidForm.reason" type="textarea" placeholder="请输入更换原因" :rows="3" maxlength="200"
            show-word-limit clearable />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitGuidChange" :loading="guidDialog.isLoading">确 定</el-button>
        <el-button @click="cancelGuidChange">取 消</el-button>
      </div>
    </el-dialog>

    <!-- GUID修改历史记录对话框 -->
    <el-dialog title="GUID修改历史记录" :visible.sync="historyDialog.open" width="800px" append-to-body>
      <div v-loading="historyDialog.isLoading" element-loading-text="正在加载历史记录...">
        <div v-if="guidHistoryList.length === 0 && !historyDialog.isLoading" class="no-data">
          <i class="el-icon-info"></i>
          <p>暂无GUID修改记录</p>
        </div>
        <el-table v-else :data="guidHistoryList" border style="width: 100%">
          <el-table-column label="序号" type="index" width="60" align="center" />
          <el-table-column label="修改前GUID" align="center" prop="jguid" show-overflow-tooltip />
          <el-table-column label="修改后GUID" align="center" prop="xguid" show-overflow-tooltip />
          <el-table-column label="修改时间" align="center" prop="createTime" width="180">
            <template slot-scope="scope">
              {{ formatDateTime(scope.row.createTime) }}
            </template>
          </el-table-column>
          <el-table-column label="原因" align="center" prop="reason" show-overflow-tooltip>
            <template slot-scope="scope">
              {{ scope.row.reason || '-' }}
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button @click="historyDialog.open = false">关 闭</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listAdsl, getAdsl, delAdsl, addAdsl, updateAdsl, exportAdsl, importAdsl, changeGuid, getChangeLog } from "@/api/door/adsl"
import { deptTreeSelect } from "@/api/system/user"
import { getToken } from "@/utils/auth"
import { Splitpanes, Pane } from "splitpanes"
import "splitpanes/dist/splitpanes.css"



export default {
  name: "Adsl",
  components: { Splitpanes, Pane },
  data() {
    return {
      // 表格高度
      tableHeight: 500,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 显示高级搜索条件
      showAdvanced: false,
      // 默认展开的节点keys（展开到区级别）
      defaultExpandedKeys: [],
      // 当前选中的节点key，用于状态保存
      currentSelectedNodeKey: null,
      // 总条数
      total: 0,
      // ADSL资料表格数据
      adslList: [],
      // 弹出层标题
      title: "",
      // 部门名称
      deptName: "",
      // 是否显示弹出层
      open: false,
      // 部门树配置选项
      defaultProps: {
        children: "children",
        label: "label"
      },
      // 部门树选项
      deptOptions: undefined,
      // 过滤掉已禁用部门树选项
      enabledDeptOptions: undefined,
      // 地址树形选项
      addressTreeOptions: [],
      // 上传的文件
      uploadFile: null,
      // 上传文件名
      uploadFileName: "",
      // 文件上传参数
      upload: {
        // 是否显示弹出层
        open: false,
        // 弹出层标题
        title: "",
        // 是否正在导入
        isUploading: false,
        // 当前状态文本
        statusText: "准备上传文件...",
        // 进度百分比
        progress: 0,
        // 进度状态
        progressStatus: null
      },
      // GUID修改对话框参数
      guidDialog: {
        open: false,
        isLoading: false
      },
      // GUID修改表单
      guidForm: {
        id: null,
        currentGuid: "",
        xguid: "",
        reason: ""
      },
      // GUID历史记录对话框参数
      historyDialog: {
        open: false,
        isLoading: false
      },
      // GUID历史记录列表
      guidHistoryList: [],

      // 固定列移除定时器
      fixedColumnTimer: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        htbh: null,
        deptId: null,
        country: null,
        province: null,
        city: null,
        district: null,
        street: null,
        village: null,
        countryName: null,
        provinceName: null,
        landlordName: null,
        landlordPhone: null,
        cityName: null,
        districtName: null,
        streetName: null,
        villageName: null,
        adsljrh: null,
        kdzh: null,
        sgk: null,
        jzxm: null,
        sfzs: null,
        sfzbmq: null,
        sfys: null,
        zsry: null,
        houseId: null,
        address: null,
        standardAddress: null,
        mjbm: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        htbh: [
          { required: true, message: "合同编号不能为空", trigger: "blur" }
        ],
        adsljrh: [
          { required: true, message: "门禁编码不能为空", trigger: "blur" }
        ],
        jzxm: [
          { required: true, message: "机主姓名不能为空", trigger: "blur" }
        ],
        sfzh: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ]
      },
      // GUID修改表单校验
      guidRules: {
        xguid: [
          { required: true, message: "新GUID不能为空", trigger: "blur" },
          { min: 1, max: 100, message: "GUID长度应在1-100个字符之间", trigger: "blur" }
        ],
        reason: [
          { required: true, message: "更换原因不能为空", trigger: "blur" },
          { min: 1, max: 200, message: "更换原因长度应在1-200个字符之间", trigger: "blur" }
        ]
      }
    }
  },
  watch: {
    // 根据名称筛选部门树
    deptName(val) {
      this.$refs.tree.filter(val)
      this.savePageState()
    }
  },
  created() {
    // 如果URL中有房产ID参数，设置到查询条件中
    if (this.$route.query.houseId) {
      this.queryParams.houseId = Number(this.$route.query.houseId)
    }
    // 获取部门树数据
    this.getDeptTree()
  },
  mounted() {
    this.calculateTableHeight()
    window.addEventListener('resize', this.calculateTableHeight)
    // 动态移除固定列，防止遮挡滚动条
    this.$nextTick(() => {
      this.removeFixedColumns()
    })
  },
  beforeDestroy() {
    window.removeEventListener('resize', this.calculateTableHeight)
    // 清除固定列移除定时器
    if (this.fixedColumnTimer) {
      clearInterval(this.fixedColumnTimer)
    }
    // 保存最终状态
    this.savePageState()
  },

  methods: {
    // 计算表格高度
    calculateTableHeight() {
      this.$nextTick(() => {
        // 计算可用高度：视窗高度 - 顶部固定高度 - 搜索区域 - 按钮区域 - 分页高度 - 边距
        const windowHeight = window.innerHeight
        const headerHeight = 124 // 顶部导航高度
        const searchCardHeight = this.showAdvanced ? 200 : 120 // 搜索区域高度（根据是否展开调整）
        const buttonAreaHeight = 60 // 按钮区域高度
        const paginationHeight = 60 // 分页高度
        const padding = 80 // 各种边距和间距

        const availableHeight = windowHeight - headerHeight - searchCardHeight - buttonAreaHeight - paginationHeight - padding
        this.tableHeight = Math.max(340, availableHeight) // 最小高度300px
      })
    },
    /** 查询ADSL资料列表 */
    getList() {
      this.loading = true
      listAdsl(this.queryParams).then(response => {
        this.adslList = response.rows
        this.total = response.total
        this.loading = false
        // 数据更新后重新移除固定列
        this.$nextTick(() => {
          this.removeFixedColumns()
        })
      })
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then(response => {
        this.deptOptions = response.data
        this.enabledDeptOptions = this.filterDisabledDept(JSON.parse(JSON.stringify(response.data)))

        // 使用部门树数据构建地址树
        this.buildAddressTreeFromDeptTree()

        // 设置默认展开的节点（展开到区级别）
        this.setDefaultExpandedKeys()

        this.$nextTick(() => {
          // 恢复之前保存的状态
          this.restorePageState()

          // 如果没有保存的状态，默认选择公司节点
          if (!this.currentSelectedNodeKey && this.deptOptions && this.deptOptions.length > 0) {
            const companyNode = this.deptOptions[0]
            this.$refs.tree.setCurrentKey(companyNode.id)
            this.currentSelectedNodeKey = companyNode.id

            // 设置公司节点的地址字段
            this.setAddressFieldsFromNode(companyNode)

            // 所有初始化工作完成后，统一请求一次数据
            this.handleQuery()
          }
        })
      }).catch(error => {
        console.error('获取部门树失败:', error)
      })
    },
    // 过滤禁用的部门
    filterDisabledDept(deptList) {
      return deptList.filter(dept => {
        if (dept.disabled) {
          return false
        }
        if (dept.children && dept.children.length) {
          dept.children = this.filterDisabledDept(dept.children)
        }
        return true
      })
    },
    // 设置默认展开的节点（展开到区级别，即第4层）
    setDefaultExpandedKeys() {
      const expandedKeys = []

      const collectKeysToLevel = (nodes, currentLevel = 0, maxLevel = 3) => {
        if (!nodes || currentLevel > maxLevel) return

        nodes.forEach(node => {
          if (currentLevel < maxLevel) {
            expandedKeys.push(node.id)
            if (node.children && node.children.length > 0) {
              collectKeysToLevel(node.children, currentLevel + 1, maxLevel)
            }
          }
        })
      }

      collectKeysToLevel(this.deptOptions)
      this.defaultExpandedKeys = expandedKeys
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true
      return data.label.indexOf(value) !== -1
    },
    // 节点单击事件
    handleNodeClick(data) {
      // 先清空deptId，因为只有村级才设置deptId
      this.queryParams.deptId = null

      // 保存当前选中的节点
      this.currentSelectedNodeKey = data.id
      this.savePageState()

      // 获取选中节点的完整路径并设置到查询参数中
      this.setAddressFieldsFromNode(data)

      this.handleQuery()
    },
    // 根据选中节点设置地址字段
    setAddressFieldsFromNode(selectedNode) {
      // 先清空所有地址字段
      this.queryParams.deptId = null
      this.queryParams.country = null
      this.queryParams.province = null
      this.queryParams.city = null
      this.queryParams.district = null
      this.queryParams.street = null
      this.queryParams.village = null
      this.queryParams.countryName = null
      this.queryParams.provinceName = null
      this.queryParams.cityName = null
      this.queryParams.districtName = null
      this.queryParams.streetName = null
      this.queryParams.villageName = null

      // 查找选中节点的完整路径
      const nodePath = this.findNodePath(this.deptOptions, selectedNode.id)

      if (nodePath && nodePath.length > 0) {
        // 获取选中节点的层级（最后一个节点的层级）
        const selectedLevel = nodePath.length - 1
        const selectedNodeData = nodePath[selectedLevel]

        // 只设置选中节点对应层级的字段（不传Name字段）
        switch (selectedLevel) {
          case 0: // 公司/国家
            this.queryParams.country = selectedNodeData.id
            break
          case 1: // 省
            this.queryParams.province = selectedNodeData.id
            break
          case 2: // 市
            this.queryParams.city = selectedNodeData.id
            break
          case 3: // 区县
            this.queryParams.district = selectedNodeData.id
            break
          case 4: // 街道/镇
            this.queryParams.street = selectedNodeData.id
            break
          case 5: // 村
            this.queryParams.village = selectedNodeData.id
            // 只有选择村的时候才设置deptId
            this.queryParams.deptId = selectedNodeData.id
            break
        }

        console.log('设置的地址字段:', {
          selectedLevel: selectedLevel,
          selectedNode: selectedNodeData.label,
          deptId: this.queryParams.deptId,
          country: this.queryParams.country,
          province: this.queryParams.province,
          city: this.queryParams.city,
          district: this.queryParams.district,
          street: this.queryParams.street,
          village: this.queryParams.village
        })
      }
    },
    // 查找节点在树中的完整路径
    findNodePath(nodes, targetId, currentPath = []) {
      if (!nodes || !Array.isArray(nodes)) return null

      for (const node of nodes) {
        const newPath = [...currentPath, node]

        if (node.id === targetId) {
          return newPath
        }

        if (node.children && node.children.length > 0) {
          const found = this.findNodePath(node.children, targetId, newPath)
          if (found) return found
        }
      }

      return null
    },
    // 构建地址树
    buildAddressTreeFromDeptTree() {
      if (!this.enabledDeptOptions) return

      // 直接使用部门树数据作为地址树
      // 如果部门树的层次结构是公司->省->市->区->街道/镇->村
      this.addressTreeOptions = JSON.parse(JSON.stringify(this.enabledDeptOptions))
    },

    // 切换高级搜索
    toggleAdvanced() {
      this.showAdvanced = !this.showAdvanced
      if (!this.showAdvanced) {
        this.resetQuery() // 收起时重置查询参数
      } else {
        this.savePageState() // 展开时保存状态
      }
      // 重新计算表格高度
      this.$nextTick(() => {
        this.calculateTableHeight()
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        houseId: null,
        htbh: null,
        countryName: null,
        provinceName: null,
        cityName: null,
        districtName: null,
        streetName: null,
        villageName: null,
        address: null,
        door: null,
        monthPrice: null,
        startDate: null,
        endDate: null,
        standardAddress: null,
        jzxm: null,
        zjlxdh: null,
        sfdsp: null,
        sfzh: null,
        xcsfzsp: null,
        jguid: null,
        oldGuid: null,
        xguid: null,
        mjgs: null,
        azsj: null,
        qm: null,
        zssj: null,
        zsry: null,
        sfzs: null,
        sfzbmq: null,
        sfys: null,
        yspc: null,
        sgk: null,
        mjbm: null,
        adsljrh: null,
        kdzh: null,
        kdmm: null,
        dxfk: null,
        fzfk: null,
        ztbz: null,
        zlbq: null,
        zlbg: null,
        tsqk: null,
        filePath: null,
        deptId: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.savePageState()
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      // 重置地址相关字段
      this.queryParams.deptId = null
      this.queryParams.country = null
      this.queryParams.province = null
      this.queryParams.city = null
      this.queryParams.district = null
      this.queryParams.street = null
      this.queryParams.village = null
      this.queryParams.countryName = null
      this.queryParams.provinceName = null
      this.queryParams.cityName = null
      this.queryParams.districtName = null
      this.queryParams.streetName = null
      this.queryParams.villageName = null
      // 重置新增的搜索字段
      this.queryParams.address = null
      this.queryParams.standardAddress = null
      this.queryParams.mjbm = null
      // 如果是从房东管理页面跳转过来，保留房东ID
      if (this.$route.query.houseId) {
        this.queryParams.houseId = Number(this.$route.query.houseId)
      }
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加资料"

      // 如果URL中有房产ID参数，设置到表单中
      if (this.$route.query.houseId) {
        this.form.houseId = Number(this.$route.query.houseId)
      }
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      console.log(row)
      const id = row.id || this.ids
      getAdsl(id).then(response => {
        // 先将原始数据保存到表单
        this.form = { ...response.data }

        // 处理公司和地址信息
        if (row.countryName) this.form.company = row.countryName
        if (row.address) this.form.address = row.address
        if (row.door) this.form.door = row.door

        // 处理地区ID
        if (row.deptId) {
          this.form.deptId = row.deptId
        } else if (row.countryName || row.provinceName ||
          row.cityName || row.districtName ||
          row.streetName || row.villageName) {
          // 尝试从地址树中找到对应的节点ID
          this.loadAddressFromTable(row)
        }

        // 处理是否带视频字段
        if (this.form.sfdsp === '是') {
          this.form.sfdsp = '1'
        } else if (this.form.sfdsp === '否') {
          this.form.sfdsp = '0'
        }

        // 处理现场是否装视频字段
        if (this.form.xcsfzsp === '是') {
          this.form.xcsfzsp = '1'
        } else if (this.form.xcsfzsp === '否') {
          this.form.xcsfzsp = '0'
        }

        // 处理是否装锁字段
        if (this.form.sfzs === '是') {
          this.form.sfzs = '1'
        } else if (this.form.sfzs === '否') {
          this.form.sfzs = '0'
        }

        // 处理是否装闭门器字段
        if (this.form.sfzbmq === '是') {
          this.form.sfzbmq = '1'
        } else if (this.form.sfzbmq === '否') {
          this.form.sfzbmq = '0'
        }

        // 处理验收状态，如果是日期格式，转为已验收
        if (this.form.sfys && this.form.sfys !== '0' && this.form.sfys !== '1') {
          this.form.sfys = '1'  // 设置为已验收
        }

        // 处理安装时间格式 20170622 -> 2017-06-22 00:00:00
        if (this.form.azsj && typeof this.form.azsj === 'string') {
          if (this.form.azsj.length === 8) {
            const year = this.form.azsj.substring(0, 4)
            const month = this.form.azsj.substring(4, 6)
            const day = this.form.azsj.substring(6, 8)
            this.form.azsj = `${year}-${month}-${day} 00:00:00`
          } else if (!this.form.azsj.includes(':')) {
            // 如果只有日期部分，添加时间部分
            this.form.azsj = `${this.form.azsj} 00:00:00`
          }
        }

        // 处理装锁时间格式
        if (this.form.zssj && typeof this.form.zssj === 'string') {
          if (this.form.zssj.length === 8) {
            const year = this.form.zssj.substring(0, 4)
            const month = this.form.zssj.substring(4, 6)
            const day = this.form.zssj.substring(6, 8)
            this.form.zssj = `${year}-${month}-${day} 00:00:00`
          } else if (!this.form.zssj.includes(':')) {
            // 如果只有日期部分，添加时间部分
            this.form.zssj = `${this.form.zssj} 00:00:00`
          }
        }

        // 更新表单
        this.open = true
        this.title = "修改资料"
      })
    },

    // 从表格行数据加载地址信息
    loadAddressFromTable(row) {
      const regionNames = []
      if (row.countryName) regionNames.push(row.countryName)
      if (row.provinceName) regionNames.push(row.provinceName)
      if (row.cityName) regionNames.push(row.cityName)
      if (row.districtName) regionNames.push(row.districtName)
      if (row.streetName) regionNames.push(row.streetName)
      if (row.villageName) regionNames.push(row.villageName)

      if (regionNames.length === 0) return

      // 递归查找地址ID路径
      const findPath = (nodes, names, level = 0, path = []) => {
        if (!nodes || nodes.length === 0) return null
        if (level >= names.length) return path

        for (const node of nodes) {
          if (node.label === names[level]) {
            const newPath = [...path, node.id]
            if (level === names.length - 1) return newPath

            if (node.children && node.children.length > 0) {
              const result = findPath(node.children, names, level + 1, newPath)
              if (result) return result
            }
          }
        }
        return null
      }

      const path = findPath(this.addressTreeOptions, regionNames)
      if (path && path.length > 0) {
        this.form.deptId = path
        console.log('地址ID路径:', path)
      }
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAdsl(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addAdsl(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除ADSL资料管理编号为"' + ids + '"的数据项？').then(function () {
        return delAdsl(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => { })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('door/adsl/export', {
        ...this.queryParams
      }, `adsl_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "ADSL资料导入";
      this.upload.open = true;
      this.uploadFile = null;
      this.uploadFileName = "";
      this.resetUploadState();
    },
    /** 下载模板操作 */
    importTemplate() {
      this.downloadTemplate("/door/adsl/importTemplate", "ADSL资料导入模板.xlsx");
    },
    // 触发文件选择
    triggerFileInput() {
      this.$refs.fileInput.click();
    },
    // 处理文件选择
    handleFileChange(e) {
      const files = e.target.files;
      if (files && files.length > 0) {
        this.uploadFile = files[0];
        this.uploadFileName = files[0].name;
      }
    },
    // 清除选择的文件
    clearUploadFile() {
      this.uploadFile = null;
      this.uploadFileName = "";
      if (this.$refs.fileInput) {
        this.$refs.fileInput.value = "";
      }
    },
    // 提交导入请求
    submitImport() {
      if (!this.uploadFile) {
        this.$message.warning("请先选择要上传的Excel文件");
        return;
      }

      this.upload.isUploading = true;
      this.upload.statusText = "正在导入数据...";
      this.upload.progress = 50;

      // 直接处理导入文件流
      importAdsl(this.uploadFile).then(response => {
        this.upload.isUploading = false;
        this.upload.progress = 100;
        this.upload.statusText = "导入完成，正在下载结果文件...";
        this.upload.progressStatus = 'success';

        // 直接下载返回的文件流
        const url = window.URL.createObjectURL(response);
        const a = document.createElement('a');
        a.href = url;
        a.download = `ADSL导入结果_${new Date().getTime()}.xlsx`;
        document.body.appendChild(a);
        a.click();
        window.URL.revokeObjectURL(url);
        document.body.removeChild(a);

        this.$message.success("导入完成，结果文件已下载");

        // 刷新列表
        this.getList();

        // 2秒后关闭对话框
        setTimeout(() => {
          this.closeImportDialog();
        }, 2000);
      }).catch(error => {
        this.upload.isUploading = false;
        this.upload.progress = 0;
        this.upload.statusText = "导入失败";
        this.upload.progressStatus = 'exception';

        console.error('导入失败:', error);
        let errorMessage = "导入失败";

        if (error.response) {
          // 如果有响应，尝试解析错误信息
          if (error.response.data && error.response.data.type === 'application/json') {
            // 如果返回的是JSON错误信息，需要转换
            const reader = new FileReader();
            reader.onload = () => {
              try {
                const errorData = JSON.parse(reader.result);
                errorMessage = errorData.msg || "导入失败";
                this.$message.error(errorMessage);
              } catch (e) {
                this.$message.error("导入失败，请检查文件格式");
              }
            };
            reader.readAsText(error.response.data);
          } else {
            errorMessage = error.response.statusText || "导入失败";
            this.$message.error(errorMessage);
          }
        } else {
          errorMessage = error.message || "网络错误";
          this.$message.error(errorMessage);
        }
      });
    },
    // 重置上传状态
    resetUploadState() {
      this.upload.isUploading = false;
      this.upload.statusText = "准备上传文件...";
      this.upload.progress = 0;
      this.upload.progressStatus = null;
    },


    // 关闭导入对话框
    closeImportDialog() {
      this.upload.open = false;
      this.resetUploadState();
      this.clearUploadFile();
    },
    /** 修改GUID按钮操作 */
    handleChangeGuid(row) {
      this.guidForm = {
        id: row.id,
        currentGuid: row.xguid || row.jguid || "",
        xguid: "",
        reason: ""
      };
      this.guidDialog.open = true;
      this.$nextTick(() => {
        if (this.$refs.guidForm) {
          this.$refs.guidForm.resetFields();
        }
      });
    },
    /** 提交GUID修改 */
    submitGuidChange() {
      this.$refs["guidForm"].validate(valid => {
        if (valid) {
          this.guidDialog.isLoading = true;
          const params = {
            id: this.guidForm.id,
            xguid: this.guidForm.xguid,
            reason: this.guidForm.reason
          };
          changeGuid(params).then(response => {
            this.guidDialog.isLoading = false;
            this.$modal.msgSuccess("GUID修改成功");
            this.guidDialog.open = false;
            this.getList(); // 刷新列表
          }).catch(error => {
            this.guidDialog.isLoading = false;
            this.$message.error("GUID修改失败: " + error.message);
          });
        }
      });
    },
    /** 取消GUID修改 */
    cancelGuidChange() {
      this.guidDialog.open = false;
      this.guidForm = {
        id: null,
        currentGuid: "",
        xguid: "",
        reason: ""
      };
      if (this.$refs.guidForm) {
        this.$refs.guidForm.resetFields();
      }
    },
    /** 查看GUID修改历史记录 */
    handleViewGuidHistory(row) {
      this.guidHistoryList = [];
      this.historyDialog.open = true;
      this.historyDialog.isLoading = true;

      const params = {
        id: row.id,
        xguid: row.xguid || row.jguid || ""
      };

      getChangeLog(params).then(response => {
        this.historyDialog.isLoading = false;
        // 假设返回的数据结构是 { data: [] } 或者直接是数组
        this.guidHistoryList = response.data || response.rows || response || [];
      }).catch(error => {
        this.historyDialog.isLoading = false;
        this.$message.error("获取GUID修改记录失败: " + (error.message || "未知错误"));
        this.guidHistoryList = [];
      });
    },
    /** 格式化日期时间 */
    formatDateTime(dateTime) {
      if (!dateTime) return '-';
      try {
        const date = new Date(dateTime);
        return date.getFullYear() + '-' +
          (date.getMonth() + 1).toString().padStart(2, '0') + '-' +
          date.getDate().toString().padStart(2, '0') + ' ' +
          date.getHours().toString().padStart(2, '0') + ':' +
          date.getMinutes().toString().padStart(2, '0') + ':' +
          date.getSeconds().toString().padStart(2, '0');
      } catch (error) {
        return dateTime;
      }
    },

    // 保存页面状态
    savePageState() {
      const state = {
        currentSelectedNodeKey: this.currentSelectedNodeKey,
        queryParams: { ...this.queryParams },
        showAdvanced: this.showAdvanced,
        deptName: this.deptName
      }
      sessionStorage.setItem('adsl_page_state', JSON.stringify(state))
    },
    // 恢复页面状态
    restorePageState() {
      const savedState = sessionStorage.getItem('adsl_page_state')
      if (savedState) {
        try {
          const state = JSON.parse(savedState)

          // 恢复选中的节点
          if (state.currentSelectedNodeKey) {
            this.currentSelectedNodeKey = state.currentSelectedNodeKey
            this.$refs.tree.setCurrentKey(state.currentSelectedNodeKey)

            // 根据选中节点设置查询参数
            const selectedNode = this.findNodeById(this.deptOptions, state.currentSelectedNodeKey)
            if (selectedNode) {
              this.setAddressFieldsFromNode(selectedNode)
            }
          }

          // 恢复搜索条件
          if (state.queryParams) {
            // 合并查询参数，保留URL中的houseId参数
            Object.assign(this.queryParams, state.queryParams)
            if (this.$route.query.houseId) {
              this.queryParams.houseId = Number(this.$route.query.houseId)
            }
          }

          // 恢复其他状态
          this.showAdvanced = state.showAdvanced || false
          this.deptName = state.deptName || ''

          // 恢复状态后查询数据
          this.handleQuery()

        } catch (error) {
          console.error('恢复页面状态失败:', error)
        }
      }
    },
    // 根据ID查找节点
    findNodeById(nodes, targetId) {
      if (!nodes || !Array.isArray(nodes)) return null

      for (const node of nodes) {
        if (node.id === targetId) {
          return node
        }

        if (node.children && node.children.length > 0) {
          const found = this.findNodeById(node.children, targetId)
          if (found) return found
        }
      }

      return null
    },
    // 温和的固定列调整
    removeFixedColumns() {
      // 暂时不执行，先恢复正常显示
    }
  }
}
</script>

<style scoped>
.main-content {
  height: calc(100vh - 124px);
  overflow: hidden;
}

.app-container {
  padding: 10px;
  height: 100%;
  overflow: hidden;
}

.default-theme {
  height: 100%;
}

.splitpanes.default-theme .splitpanes__pane {
  background-color: #fff;
  display: flex;
  flex-direction: column;
}

/* 左侧树形区域需要可滚动 */
.splitpanes.default-theme .splitpanes__pane:first-child {
  overflow-y: auto;
}

/* 右侧内容区域保持不滚动，由内部元素控制滚动 */
.splitpanes.default-theme .splitpanes__pane:last-child {
  overflow: hidden;
}

.splitpanes--vertical>.splitpanes__splitter {
  min-width: 6px;
}

/* 左侧树形区域样式 */
.tree-pane {
  padding: 15px;
}

.tree-column {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.head-container {
  flex-shrink: 0;
}

.tree-container {
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

/* 表格容器样式 */
.table-container {
  min-height: 0;
}

/* 表格样式优化 */
.el-table {
  margin-top: 8px;
}

.el-table .el-table__header th {
  background-color: #f5f7fa;
}

.el-table .el-table__row:hover {
  background-color: #f0f7ff;
}

/* 确保表格内容能够正确滚动 */
.el-table .el-table__body-wrapper {
  overflow-y: auto;
}

/* 表单样式优化 */
.el-dialog__body {
  padding: 20px 30px 10px 30px;
}

.section-title {
  font-size: 15px;
  font-weight: bold;
  margin: 10px 0;
  padding: 5px 0;
  border-bottom: 1px solid #ddd;
  color: #409EFF;
}

/* 导入对话框样式 */
.import-container {
  padding: 10px 0;
}

.import-tips {
  margin-bottom: 15px;
}

.upload-area {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: 30px 0;
  margin: 10px 0;
}

.upload-area:hover {
  border-color: #409EFF;
}

.upload-area .el-icon-upload {
  font-size: 40px;
  color: #c0c4cc;
  margin-bottom: 10px;
}

.upload-text {
  color: #606266;
  font-size: 14px;
  margin-bottom: 5px;
}

.upload-tip {
  color: #909399;
  font-size: 12px;
}

.file-info {
  display: flex;
  align-items: center;
  padding: 10px;
  border: 1px solid #e6e6e6;
  border-radius: 4px;
  margin: 10px 0;
  background-color: #f9f9f9;
}

.file-info i {
  color: #909399;
  margin-right: 8px;
  font-size: 18px;
}

.import-options {
  margin-top: 15px;
}

.el-form-item {
  margin-bottom: 15px;
}

.el-dialog .el-row {
  margin-bottom: 5px;
}

/* 搜索区域样式 */
.search-card {
  margin-bottom: 15px;
}

.search-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
}

.search-section {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
}

.basic-search {
  margin-bottom: 5px;
}

.advanced-search {
  margin-top: 5px;
  padding-top: 5px;
}

.divider {
  width: 100%;
  position: relative;
  text-align: left;
  font-size: 14px;
  height: 30px;
  margin: 5px 0;
}

.divider:before {
  content: '';
  position: absolute;
  left: 0;
  width: 100%;
  height: 1px;
  background-color: #EBEEF5;
  top: 50%;
}

.divider-title {
  position: relative;
  display: inline-block;
  background-color: white;
  padding: 0 10px 0 0;
  color: #606266;
  font-size: 13px;
  font-weight: 500;
}

/* 历史记录无数据样式 */
.no-data {
  text-align: center;
  padding: 40px 0;
  color: #909399;
}

.no-data i {
  font-size: 40px;
  margin-bottom: 15px;
  display: block;
}

.no-data p {
  margin: 0;
  font-size: 14px;
}

/* 分页样式优化 */
.el-pagination {
  text-align: center;
  padding: 10px 0;
  background-color: #fff;
  border-top: 1px solid #ebeef5;
}

/* 导入进度样式 */
.import-progress {
  padding: 20px 0;
}

.progress-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  font-size: 16px;
  color: #606266;
}

.progress-header i {
  margin-right: 8px;
  color: #409EFF;
  animation: rotate 2s linear infinite;
}

@keyframes rotate {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

.progress-details {
  margin-top: 20px;
  padding: 15px;
  background-color: #f5f7fa;
  border-radius: 4px;
}

.detail-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.detail-item:last-child {
  margin-bottom: 0;
}

.detail-item .label {
  color: #606266;
  font-weight: 500;
}

.detail-item .value {
  font-weight: bold;
}

.detail-item .value.success {
  color: #67c23a;
}

.detail-item .value.error {
  color: #f56c6c;
}

.import-log {
  margin-top: 15px;
}

.log-content {
  max-height: 200px;
  overflow-y: auto;
  padding: 10px;
  background-color: #f8f9fa;
  border-radius: 4px;
  font-size: 13px;
  line-height: 1.5;
  color: #606266;
}

/* 进度条样式调整 */
.el-progress {
  margin: 10px 0;
}

.el-progress__text {
  font-weight: bold;
}

/* 表格滚动条样式优化 - 应用到所有滚动容器 */
.el-table ::-webkit-scrollbar {
  width: 20px !important;
  height: 20px !important;
}

.el-table ::-webkit-scrollbar-track {
  background: #e8e8e8 !important;
  border-radius: 10px !important;
}

.el-table ::-webkit-scrollbar-thumb {
  background: #666 !important;
  border-radius: 10px !important;
  border: 4px solid #e8e8e8 !important;
  min-height: 40px !important;
  min-width: 40px !important;
}

.el-table ::-webkit-scrollbar-thumb:hover {
  background: #333 !important;
}

.el-table ::-webkit-scrollbar-corner {
  background: #e8e8e8 !important;
}

/* 专门针对表格主体滚动条 */
.el-table .el-table__body-wrapper::-webkit-scrollbar {
  width: 20px !important;
  height: 20px !important;
}

.el-table .el-table__body-wrapper::-webkit-scrollbar-track {
  background: #e8e8e8 !important;
  border-radius: 10px !important;
}

.el-table .el-table__body-wrapper::-webkit-scrollbar-thumb {
  background: #666 !important;
  border-radius: 10px !important;
  border: 4px solid #e8e8e8 !important;
  min-height: 40px !important;
}

.el-table .el-table__body-wrapper::-webkit-scrollbar-thumb:hover {
  background: #333 !important;
}

.el-table .el-table__body-wrapper::-webkit-scrollbar-corner {
  background: #e8e8e8 !important;
}

/* 简化的滚动条样式，无固定列冲突 */

/* 最终解决方案：创建滚动条专用通道 */
.table-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.table-wrapper::after {
  content: '';
  position: absolute;
  bottom: 0;
  right: 0;
  width: 25px;
  height: 25px;
  background: transparent;
  z-index: 9999;
  pointer-events: none;
}

/* 确保滚动条在最顶层 */
.el-table .el-table__body-wrapper {
  z-index: 10000 !important;
  position: relative !important;
}

/* 固定列让出右下角空间 */
.el-table .el-table__fixed {
  bottom: 25px !important;
  height: calc(100% - 25px) !important;
  z-index: 1 !important;
}

.el-table .el-table__fixed-right {
  bottom: 25px !important;
  right: 25px !important;
  height: calc(100% - 25px) !important;
  z-index: 1 !important;
}

/* 表格字体加粗加大 */
.el-table {
  font-size: 15px;
  font-weight: 500;
}

.el-table th,
.el-table td {
  font-size: 15px;
  font-weight: 500;
}

.el-table .el-table__header th {
  font-size: 18px;
  font-weight: 700;
  height: 48px;
}

.el-table .cell {
  font-size: 15px;
  font-weight: 500;
  line-height: 1.5;
}

/* 操作按钮字体也加粗 */
.el-table .el-button--mini {
  font-size: 13px;
  font-weight: 600;
}

.el-table {
  .el-table__fixed {
    height: auto !important;
    bottom: 17px !important;
  }
}
</style>
